package com.sporteamws;

import com.appengine.utils.UIUtils;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Vibrator;
import android.util.Log;
import android.widget.Toast;

public class NetworkManager extends BroadcastReceiver {
	
	public Vibrator v;
			
	@Override
	public void onReceive(Context context, Intent intent) {
		/*
		try {
			
			Activity a = (Activity)context;
			// Get instance of Vibrator from current Context
			v = (Vibrator) a.getSystemService(Context.VIBRATOR_SERVICE);
					
			Log.d("app", "Network connectivity change");

			if (intent.getExtras() != null) {
				@SuppressWarnings("deprecation")
				NetworkInfo ni = (NetworkInfo) intent.getExtras().get(
						ConnectivityManager.EXTRA_NETWORK_INFO);
				if (ni != null && ni.getState() == NetworkInfo.State.CONNECTED) {
					Log.i("app", "Network " + ni.getTypeName() + " connected");

				}
			}
			if (intent.getExtras().getBoolean(
					ConnectivityManager.EXTRA_NO_CONNECTIVITY, Boolean.FALSE)) 
			{
				Log.d("app", "There's no network connectivity");

			}
			
			executeSOSvibration();
			
		} catch (Exception e) {
                Log.e("error",e.toString());
		}
		
		*/
	}
	
	public void executeSOSvibration()
	{

		// This example will cause the phone to vibrate "SOS" in Morse Code
		// In Morse Code, "s" = "dot-dot-dot", "o" = "dash-dash-dash"
		// There are pauses to separate dots/dashes, letters, and words
		// The following numbers represent millisecond lengths
		int dot = 200;      // Length of a Morse Code "dot" in milliseconds
		int dash = 500;     // Length of a Morse Code "dash" in milliseconds
		int short_gap = 200;    // Length of Gap Between dots/dashes
		int medium_gap = 500;   // Length of Gap Between Letters
		int long_gap = 1000;    // Length of Gap Between Words
		long[] pattern = {
		    0,  // Start immediately
		    dot, short_gap, dot, short_gap, dot,    // s
		    medium_gap,
		    dash, short_gap, dash, short_gap, dash, // o
		    medium_gap,
		    dot, short_gap, dot, short_gap, dot,    // s
		    long_gap
		};
		 
		// Only perform this pattern one time (-1 means "do not repeat")
		v.vibrate(pattern, -1);
	}
}
